<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input id="input" type="text" />
    <ul>
        <li>1</li>
    </ul>

    <script src="libs/zepto/zepto.js"></script>
    <script src="libs/zepto/ajax.js"></script>
    <script src="libs/zepto/event.js"></script>
    <script>
        
        function getData(value) {
            //ajax
            console.log("getData");
            console.log(value);

            $.ajax({
                url: `/search.json?s=${value}`,
                success: function (res) {
                    console.log(res.data, '<--res.data');
                }
            });
        }

        function debounce(fun, delay) {
            var timer;
            return function (args) {
                console.log(this, '<-----');
                var that = this;
                clearTimeout(timer);
                timer = setTimeout(function () {
                    fun.call(that, args)
                },delay)
            }
        }

        var debounceInput = debounce(getData, 1000);

 
        $('#input').off('keyup').on('keyup', function (e) {
            // getData($(this).val());
            
            debounceInput($(this).val());
        })
        


    </script>
    
</body>
</html>